package sholmes.euler.problem1;
/**
 * If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.	
 * Find the sum of all the multiples of 3 or 5 below 1000.
 * @author sholmes
 *
 */
public class Problem1 {
	
	/**
	 * @param args
	 */
	public static int MAX_THREASHOLD  = 1000;
	
	public static void main(String[] args) {	
		
		//General Class to calculate the sum of multiples of a number
		SumofNaturals son = new SumofNaturals(MAX_THREASHOLD);	
		
		
		System.out.println("(Generalized Solution)	    Sum of Natural Numbers to " + MAX_THREASHOLD +  ": " + son.getSumofNaturals(3,5));
		System.out.println("(More Optimized Solution)   Sum of Natural Numbers to " + MAX_THREASHOLD +  ": " + optimizedSlution());
	}
	
	/*
	 * Runtime: O(n)
	 * Returns the Sum of multiples of 3/5 upto the MAX_THRESHOLD. 
	 */
	public static int optimizedSlution(){
		//math behind 3/5 multiples
		int valueAdded = 0;
		int sum = 0;
		for(int inc = 0; inc < MAX_THREASHOLD; ++inc){
			if(((inc % 3 ==0) || (inc % 5 == 0)) && ( inc != valueAdded)){
				sum +=inc;
				valueAdded=inc;
			}
		}
		return sum;
	}
}


